{% extends 'layout/basic.html' %}
{% load static %}

{% block title %}
项目管理
{% endblock %}

{% block content %}
    <div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
                注册
            </div>
            <div class="panel-body">
                <form class="form-horizontal" method="post" novalidate>
                    {% csrf_token %}
                    {% for field in form %}
                        {% if field.name == 'code' %}
                            <div class="form-group">
                                <label class="col-sm-2 control-label"
                                       for="{{ field.id_for_label }}">{{ field.label }}</label>
                                <div class="clearfix col-sm-10">
                                    <div class="col-md-6" style="padding-left: 0;">{{ field }}</div>
                                    <div class="col-md-6"><input type="button" class="btn btn-default" id="btnGetCode"
                                                                 value="点击获取验证码"></div>
                                </div>
                            </div>
                        {% else %}
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{{ field.label }}</label>
                                <div class="col-sm-10">
                                    {{ field }}
                                    <span style="color: #f60202">{{ field.errors.0 }}</span>
                                </div>
                            </div>
                        {% endif %}
                    {% endfor %}

                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary">注 册</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script type="text/javascript">
        $(function (){
            bindBtnGetCodeEvent();
        })
        function bindBtnGetCodeEvent() {
            $('#btnGetCode').click(function (){
                $.ajax({
                    url:'/test/register/get_code/',
                    type:'Get',
                    success:function (res){
                        alert(res.data)
                    },
                    error:function (){
                        alert("ajax提交失败！")
                    }
                })
            });
        }
    </script>
{% endblock %}